//###############
//FILE : FileDatabase.java
//WRITER : Daniel Lowengrub, daniel_i_l, 320687098
//EXERCISE : oop ex3 2011
//DESCRIPTION:
//See below
//###############
package oop.ex3.filemanager;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.util.ArrayList;

/**
 * This interface rovides access to a list of files. It allows the user to add and
 * remove files. In addition, the user can get a stream from the files for reading and
 * writing. There're also commands for checking the number of streams currently reading
 * from a file and for setting streaming permissions.
 * @author daniel
 */
public interface FileDatabase {

    /**
     * Get a list of the names of all the files.
     * @return A list of file names.
     */
    ArrayList<String> getFileNames();

    /**
     * Get a list of the names of all the files sorted in lexicographical order.
     * @return A list of file names.
     */
    ArrayList<String> getSortedFileNames();
    /**
     * Check if a certain file is present.
     * @param fileName The name of the file to check for.
     * @return True iff the file exists.
     */
    boolean hasFile(String fileName);

    /**
     * Remove a file from the DB.
     * @param fileName The file to remove.
     * @return True iff the removal was successful.
     */
    boolean removeFile(String fileName);

    /**
     * Rename a file in the DB.
     * @param fileName The file to rerename.
     * @return True iff the renaming was successful.
     */
    boolean renameFile(String oldFile, String newFile);

    /**
     * This is used inorder to write to a specific file in the database
     * or to create a new file.
     * @param fileName The file to write to.
     * @return A stream that can be used to write to the file.
     */
    FileOutputStream createNewFile(String fileName);

    /**
     * Check if a file has been fully created.
     * @param fileName The file to check.
     * @return True iff the file has finished creation.
     */
    boolean finishedCreation(String fileName);

    /**
     * Set the file creation status. This should be set to true when the file
     * has finished being created.
     * @param fileName The file to set.
     * @param status True indicates that the file has finished being created.
     */
    void setCreationStatus(String fileName, boolean status);

    /**
     * Get a stream that can be used to read from a file.
     * @param fileName The file to read.
     * @return The file stream.
     */
    FileInputStream getFileStream(String fileName);

    /**
     * Get the length of a file.
     * @param fileName The file to get the length of.
     * @return The file length.
     */
    long getFileLength(String fileName);

    /**
     * Check if a file is currently being streamed. This should be checked before
     * a file is removed.
     * @param fileName The file to check.
     * @return True iff the file is being streamed.
     */
    boolean currentlyStreaming(String fileName);

    /**
     * Get the number of streams currently reading the file.
     * @param fileName The file to get the number of streams from.
     * @return The number of streams.
     */
    public int getNumberOfStreams(String fileName);

    /**
     * Add one to the number of streams reading from a file. This should be called
     * before opening a stream.
     * @param fileName The file that the stream should be added to.
     */
    void addStream(String fileName);

    /**
     * Remove one from the number of streams. This should be done after finishing
     * reading from a file.
     * @param fileName The file that the stream will be removed from.
     */
    void removeStream(String fileName);

    /**
     * Checks if we have permission to stream from a file.
     * @param fileName The file to check for permission.
     * @return True iff we are allowed to stream.
     */
    boolean streamingPermission(String fileName);

    /**
     * Set the streaming permission for a file. This should be set to false
     * if no new streams should be opened.
     * @param fileName The file to set permissions on.
     * @param permission True if there's permission and false otherwise.
     */
    void setStreamingPermission(String fileName, boolean permission);
}
